cmake_minimum_required(VERSION 3.31)
project(newTest)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "D:/ide/qt/5.14.2/msvc2017_64")
# 目录plugins

set(PLUGIN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plugins)

set(PLUGIN_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plugins)

# 主程序的编译输出目录
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}")

# 创建 plugins 目录（确保目录存在）
file(MAKE_DIRECTORY "${APP_BIN_DIR}/plugins")

file(COPY ${PLUGIN_BUILD_DIR}/new.dll
        DESTINATION ${APP_BIN_DIR}/plugins)

file(COPY ${PLUGIN_BUILD_DIR}/SqlUtil.dll
        DESTINATION ${APP_BIN_DIR}/plugins)

#file(COPY ${PLUGIN_BUILD_DIR}/CutPlugin.dll
#        DESTINATION ${APP_BIN_DIR}/plugins)


find_package(Qt5 COMPONENTS
        Core
        Gui
        Widgets
        Sql
        REQUIRED)

add_executable(newTest main.cpp
        IMessage.h
        manage/PluginManger.cpp
        manage/PluginManger.h
        manage/header.h
        manage/ISourcePlugin.h
        plugins/IDataBasePlugin.h
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        ../sql/QSqlQueryUtil.h
        worker/Worker.cpp
        worker/Worker.h

)

target_link_libraries(newTest
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Sql
)

# 复制 SQL 驱动插件
if (EXISTS "${QT_INSTALL_PATH}/plugins/sqldrivers/")
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E make_directory
            "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/sqldrivers/")
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory
            "${QT_INSTALL_PATH}/plugins/sqldrivers/"
            "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/sqldrivers/")
endif ()

